import Types from '../../action/Types';

const defaultState = {};

export default function trendingReducer (state = defaultState, action) {
  switch (action.type) {
    case Types.TRENDING_REFRESH: // 刷新中
      return {
        ...state,
        [action.storeName]: {
          ...state[action.storeName],
          isLoading: true,
          hideLoadMore: true
        }
      };
    case Types.TRENDING_REFRESH_SUCCESS: // 刷新成功
      return {
        ...state,
        [action.storeName]: {
          ...state[action.storeName],
          items: action.items,
          allItems: action.allItems,
          pageIndex: action.pageIndex,
          isLoading: false,
          hideLoadMore: false
        }
      };
    case Types.TRENDING_REFRESH_FAILURE: // 刷新失败
      return {
        ...state,
        [action.storeName]: {
          ...state[action.storeName],
          isLoading: false
        }
      };
    case Types.TRENDING_LOAD_MORE_SUCCESS: // 上拉加载更多
      return {
        ...state,
        [action.storeName]: {
          ...state[action.storeName],
          items: action.items,
          pageIndex: action.pageIndex,
          hideLoadMore: false,
        }
      };
    case Types.TRENDING_LOAD_MORE_FAILURE: // 上拉加载失败(已加载全部数据)
      return {
        ...state,
        [action.storeName]: {
          ...state[action.storeName],
          pageIndex: action.pageIndex,
          hideLoadMore: true,
        }
      };
    default:
      return state;
  }
}